/*
* Copyright 2004-2010 mb_sx@hotmail.com
* All Rights Reserved.
*/
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace DeskNotes
{
	/// <summary>
	/// Summary description for WinImports.
	/// </summary>
	public class WinImports
	{
        [DllImport("User32.dll")]
        public static extern Int32 GetSystemMetrics(Int32 nIndex);

		[DllImport("User32.dll")]
		public static extern IntPtr GetForegroundWindow();

		[DllImport("User32.dll")]
		public static extern Int32 GetWindowLong(IntPtr hWnd, Int32 nIndex);

		[DllImport("User32.dll")]
		public static extern Int32 SetWindowLong(IntPtr hWnd, Int32 nIndex, Int32 dwNewLong);
		
		[DllImport("User32.dll")]
		public static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
			Int32 X, Int32 Y, Int32 cx, Int32 cy, UInt32 uFlags );

		[DllImport("User32.dll")]
		public static extern IntPtr GetDesktopWindow();

		[DllImport("User32.dll")]
		public static extern Boolean SetForegroundWindow(IntPtr hWnd);

		[DllImport("User32.dll")]
		public static extern IntPtr SetParent(IntPtr child, IntPtr newParent);

		[DllImport("User32.dll")]
		public static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);

		[DllImport("User32.dll")]
			public static extern IntPtr SetActiveWindow(IntPtr hWnd);

        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct Point
        {

            /// LONG->int
            public int x;

            /// LONG->int
            public int y;
        }

       /// Return Type: BOOL->int
       ///lpPoint: LPPOINT->tagPOINT*
       [DllImport("User32.dll")]
       [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
       public static extern bool GetCursorPos([System.Runtime.InteropServices.OutAttribute()] out Point lpPoint);
       


		//PlaySound API can be used to play a wav file. long needs to be fixed according to mapping table.
		[DllImport("winmm.dll")]
		public static extern long PlaySound(String lpszName, long hModule, long dwFlags);

		[DllImport("User32.dll")]
		public static extern Boolean MessageBeep( UInt32 beepType);

        [DllImport("Shell32.dll")]
        public static extern IntPtr ShellExecute(IntPtr hwnd, String lpOperation, String lpFile,
            String lpParameters, String lpDirectory, Int32 nShowCmd);

        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", EntryPoint = "GetDeviceCaps")]
        public static extern int GetDeviceCaps([System.Runtime.InteropServices.InAttribute()] System.IntPtr hdc, int index);


        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        public static extern IntPtr SendMessage(System.Runtime.InteropServices.HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam);

        public const int LOGPIXELSX = 88;
        public const long TwipsPerInch = 1440;
		 
		public static uint Ok				= 0x00000000;
		public static uint IconHand			= 0x00000010;
		public static uint IconQuestion		= 0x00000020;
		public static uint IconExclamation	= 0x00000030;
		public static uint IconAsterisk		= 0x00000040;
		
		public static int HWND_TOP = 0;
		public static int HWND_TOPMOST = -1;
		public static int HWND_NOTOPMOST = -2;

		public static int GWL_STYLE       =   -16;
		public static int GWL_EXSTYLE       =   -20;

		public static int WS_CAPTION = 0x00C00000;
		public static int WS_BORDER =  0x00800000;
		public static int WS_THICKFRAME = 0x00040000;
		public static int WS_VISIBLE = 0x10000000;
		public static int WS_EX_LAYERED = 0x00080000;
		public static int WS_EX_NOACTIVATE = 0x08000000;
		public static int WS_EX_APPWINDOW = 0x00040000;

		public static uint SWP_FRAMECHANGED = 0x0020;
		public static uint SWP_NOSIZE = 0x0001;
		public static uint SWP_NOMOVE = 0x0002;
		public static uint SWP_NOZORDER = 0x0004;
		public static uint SWP_HIDEWINDOW = 0x0080;
		public static uint SWP_NOOWNERZORDER = 0x0200;

		public static int SW_SHOWNOACTIVATE = 4;

        // index values for GetSystemMetrics()
        public static int SM_CXBORDER = 5;
        public static int SM_CXEDGE = 45;
        public static int SM_CXFIXEDFRAME = 7;
        public static int SM_CXFOCUSBORDER = 83;
        public static int SM_CXSIZEFRAME = 32;
        public static int SM_CYCAPTION = 4;

          //Then some code to do numbering. 

        #region PARAFORMAT MASK VALUES
        // PARAFORMAT mask values 
        public static uint PFM_STARTINDENT = 0x00000001;
        public static uint PFM_RIGHTINDENT = 0x00000002;
        public static uint PFM_OFFSET = 0x00000004;
        public static uint PFM_ALIGNMENT = 0x00000008;
        public static uint PFM_TABSTOPS = 0x00000010;
        public static uint PFM_NUMBERING = 0x00000020;
        public static uint PFM_OFFSETINDENT = 0x80000000;

        // PARAFORMAT 2.0 masks and effects 
        public static uint PFM_SPACEBEFORE = 0x00000040;
        public static uint PFM_SPACEAFTER = 0x00000080;
        public static uint PFM_LINESPACING = 0x00000100;
        public static uint PFM_STYLE = 0x00000400;
        public static uint PFM_BORDER = 0x00000800; // (*) 
        public static uint PFM_SHADING = 0x00001000; // (*) 
        public static uint PFM_NUMBERINGSTYLE = 0x00002000; // RE 3.0 
        public static uint PFM_NUMBERINGTAB = 0x00004000; // RE 3.0 
        public static uint PFM_NUMBERINGSTART = 0x00008000; // RE 3.0 

        public static uint PFM_RTLPARA = 0x00010000;
        public static uint PFM_KEEP = 0x00020000; // (*) 
        public static uint PFM_KEEPNEXT = 0x00040000; // (*) 
        public static uint PFM_PAGEBREAKBEFORE = 0x00080000; // (*) 
        public static uint PFM_NOLINENUMBER = 0x00100000; // (*) 
        public static uint PFM_NOWIDOWCONTROL = 0x00200000; // (*) 
        public static uint PFM_DONOTHYPHEN = 0x00400000; // (*) 
        public static uint PFM_SIDEBYSIDE = 0x00800000; // (*) 
        public static uint PFM_TABLE = 0x40000000; // RE 3.0 
        public static uint PFM_TEXTWRAPPINGBREAK = 0x20000000; // RE 3.0 
        public static uint PFM_TABLEROWDELIMITER = 0x10000000; // RE 4.0 

        // The following three properties are read only 
        public static uint PFM_COLLAPSED = 0x01000000; // RE 3.0 
        public static uint PFM_OUTLINELEVEL = 0x02000000; // RE 3.0 
        public static uint PFM_BOX = 0x04000000; // RE 3.0 
        public static uint PFM_RESERVED2 = 0x08000000; // RE 4.0 

        public enum AdvRichTextBulletType
        {
            NoList = 0,
            Normal = 1,
            Number = 2,
            LowerCaseLetter = 3,
            UpperCaseLetter = 4,
            LowerCaseRoman = 5,
            UpperCaseRoman = 6
        }

        public enum AdvRichTextBulletStyle
        {
            RightParenthesis = 0x000,
            DoubleParenthesis = 0x100,
            Period = 0x200,
            Plain = 0x300,
            NoNumber = 0x400
        }
        #endregion

        public const int WM_USER = 0x0400;
        public const int EM_FORMATRANGE = WM_USER + 57;
        public const int EM_GETPARAFORMAT = WM_USER + 61;
        public const int EM_SETPARAFORMAT = WM_USER + 71;
    }

    [StructLayout(LayoutKind.Sequential)]
    public class PARAFORMAT2
    {
        public int cbSize;
        public int dwMask;
        public short wNumbering;
        public short wReserved;
        public int dxStartIndent;
        public int dxRightIndent;
        public int dxOffset;
        public short wAlignment;
        public short cTabCount;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)]
        public int[] rgxTabs;

        public int dySpaceBefore; // Vertical spacing before para 
        public int dySpaceAfter; // Vertical spacing after para 
        public int dyLineSpacing; // Line spacing depending on Rule 
        public short sStyle; // Style handle 
        public byte bLineSpacingRule; // Rule for line spacing (see tom.doc) 
        public byte bOutlineLevel; // Outline Level 
        public short wShadingWeight; // Shading in hundredths of a per cent 
        public short wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat 
        public short wNumberingStart; // Starting value for numbering 
        public short wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc. 
        public short wNumberingTab; // Space bet 1st indent and 1st-line text 
        public short wBorderSpace; // Border-text spaces (nbl/bdr in pts) 
        public short wBorderWidth; // Pen widths (nbl/bdr in half twips) 
        public short wBorders; // Border styles (nibble/border) 

        public PARAFORMAT2()
        {
            this.cbSize = Marshal.SizeOf(typeof(PARAFORMAT2));
        }
    
	}
}
